//
//  HeadView.m
//  Rac
//
//  Created by ios on 2017/3/22.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "HeadView.h"

@interface HeadView ()


@end
@implementation HeadView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        @weakify(self)
        _btnSingle = [RACSubject subject];
        
        self.backgroundColor = [UIColor whiteColor];
        _bgLabel = [[UILabel alloc] init];
        
        [self addSubview:_bgLabel];
        
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_btn setTitle:@"按钮" forState:UIControlStateNormal];
        [_btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        _btn.tag = 100;
        
        [[_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            @strongify(self);
            
            UIButton *btn = x;
            
            [_btnSingle sendNext:[NSNumber numberWithInteger:btn.tag]];
            
        }];
        
        [self addSubview:_btn];
        
    }
    return self;
}


-(void)layoutSubviews{
    CGFloat viewW = self.frame.size.width;
    CGFloat viewH = self.frame.size.height;
    
    _bgLabel.frame = CGRectMake(0, 0, viewW, viewH/2);
    
    _btn.frame     = CGRectMake(0, viewH/2, viewW,viewH/2);
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
